package com.example.usbprinter;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;
import android.util.Log;


public class USBBroadCastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("USBBroadCastReceiver", "onReceive: ");
        if (intent.getAction() != null)
            switch (intent.getAction()) {
                case UsbManager.ACTION_USB_DEVICE_ATTACHED:
                    USBPrinter.startDiscovery(context);
                    break;
                case UsbManager.ACTION_USB_DEVICE_DETACHED:
                    USBPrinter.stopDiscovery();
                    break;
                default:
                    break;
            }
    }
}
